home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dtadmo / form2.frm < prev    next >
Text File  |  1994-10-15  |  8KB  |  293 lines

  1. VERSION 2.00
  2. Begin Form Form2 
  3.    Caption         =   "Form2"
  4.    ClientHeight    =   4260
  5.    ClientLeft      =   1110
  6.    ClientTop       =   1500
  7.    ClientWidth     =   7365
  8.    Height          =   4665
  9.    Left            =   1050
  10.    LinkTopic       =   "Form2"
  11.    ScaleHeight     =   4260
  12.    ScaleWidth      =   7365
  13.    Top             =   1155
  14.    Width           =   7485
  15.    Begin CommandButton cmdClose 
  16.       Caption         =   "Close"
  17.       Height          =   495
  18.       Left            =   120
  19.       TabIndex        =   14
  20.       Top             =   3480
  21.       Width           =   1455
  22.    End
  23.    Begin CommandButton cmdDelete 
  24.       Caption         =   "Delete"
  25.       Height          =   495
  26.       Left            =   6120
  27.       TabIndex        =   13
  28.       Top             =   3480
  29.       Width           =   1215
  30.    End
  31.    Begin CommandButton cmdUpdate 
  32.       Caption         =   "Update"
  33.       Height          =   495
  34.       Left            =   4440
  35.       TabIndex        =   12
  36.       Top             =   3480
  37.       Width           =   1215
  38.    End
  39.    Begin CommandButton cmdNew 
  40.       Caption         =   "New"
  41.       Height          =   495
  42.       Left            =   3120
  43.       TabIndex        =   11
  44.       Top             =   3480
  45.       Width           =   1215
  46.    End
  47.    Begin CommandButton cmdFind 
  48.       Caption         =   "Find"
  49.       Height          =   495
  50.       Left            =   1800
  51.       TabIndex        =   10
  52.       Top             =   3480
  53.       Width           =   1215
  54.    End
  55.    Begin TextBox Text1 
  56.       DataSource      =   "Data1"
  57.       Height          =   495
  58.       Index           =   4
  59.       Left            =   1800
  60.       TabIndex        =   4
  61.       Text            =   "Text1"
  62.       Top             =   2520
  63.       Width           =   1215
  64.    End
  65.    Begin TextBox Text1 
  66.       DataSource      =   "Data1"
  67.       Height          =   495
  68.       Index           =   3
  69.       Left            =   1800
  70.       TabIndex        =   3
  71.       Text            =   "Text1"
  72.       Top             =   1920
  73.       Width           =   1215
  74.    End
  75.    Begin TextBox Text1 
  76.       DataSource      =   "Data1"
  77.       Height          =   495
  78.       Index           =   2
  79.       Left            =   1800
  80.       TabIndex        =   2
  81.       Text            =   "Text1"
  82.       Top             =   1320
  83.       Width           =   1215
  84.    End
  85.    Begin TextBox Text1 
  86.       DataSource      =   "Data1"
  87.       Height          =   495
  88.       Index           =   1
  89.       Left            =   1800
  90.       TabIndex        =   1
  91.       Text            =   "Text1"
  92.       Top             =   720
  93.       Width           =   1215
  94.    End
  95.    Begin TextBox Text1 
  96.       DataSource      =   "Data1"
  97.       Height          =   495
  98.       Index           =   0
  99.       Left            =   1800
  100.       TabIndex        =   0
  101.       Text            =   "Text1"
  102.       Top             =   120
  103.       Width           =   5295
  104.    End
  105.    Begin Data Data1 
  106.       Caption         =   "Data1"
  107.       Connect         =   ""
  108.       DatabaseName    =   ""
  109.       Exclusive       =   0   'False
  110.       Height          =   270
  111.       Left            =   1800
  112.       Options         =   0
  113.       ReadOnly        =   0   'False
  114.       RecordSource    =   ""
  115.       Top             =   3120
  116.       Width           =   3855
  117.    End
  118.    Begin Label Label1 
  119.       Caption         =   "Label1"
  120.       Height          =   495
  121.       Index           =   4
  122.       Left            =   480
  123.       TabIndex        =   9
  124.       Top             =   2520
  125.       Width           =   1215
  126.    End
  127.    Begin Label Label1 
  128.       Caption         =   "Label1"
  129.       Height          =   495
  130.       Index           =   3
  131.       Left            =   480
  132.       TabIndex        =   8
  133.       Top             =   1920
  134.       Width           =   1215
  135.    End
  136.    Begin Label Label1 
  137.       Caption         =   "Label1"
  138.       Height          =   495
  139.       Index           =   2
  140.       Left            =   480
  141.       TabIndex        =   7
  142.       Top             =   1320
  143.       Width           =   1215
  144.    End
  145.    Begin Label Label1 
  146.       Caption         =   "Label1"
  147.       Height          =   495
  148.       Index           =   1
  149.       Left            =   480
  150.       TabIndex        =   6
  151.       Top             =   720
  152.       Width           =   1215
  153.    End
  154.    Begin Label Label1 
  155.       Caption         =   "Label1"
  156.       Height          =   495
  157.       Index           =   0
  158.       Left            =   480
  159.       TabIndex        =   5
  160.       Top             =   120
  161.       Width           =   1215
  162.    End
  163. End
  164. Option Explicit
  165.  
  166. Sub cmdClose_Click ()
  167.     Unload form2
  168.     'database is closed in the form unload event
  169. End Sub
  170.  
  171. Sub cmdDelete_Click ()
  172. 'reminder:
  173. 'Global Const MB_YESNO = 4              ' Yes and No buttons
  174. 'Global Const IDYES = 6                 ' Yes button pressed
  175. 'Global Const MB_DEFBUTTON2 = 256       ' Second button is default
  176.  
  177.     On Error GoTo cmddeleteERR
  178.     Dim response As Integer
  179.     response = MsgBox("Are sure you want to delete " & text1(0).Text & " ?", MB_YESNO + MB_DEFBUTTON2)
  180.     If response = IDYES Then
  181.     data1.Recordset.Delete
  182.     'refresh so our deleted record isn't still showing
  183.     'on screen
  184.     data1.Refresh
  185.     End If
  186.  
  187. GoTo cmddeleteEND
  188. cmddeleteERR:
  189.     showerror
  190.     Resume cmddeleteEND
  191. cmddeleteEND:
  192.  
  193. End Sub
  194.  
  195. Sub cmdFind_Click ()
  196.     On Error GoTo cmdfindERR
  197.  
  198.     Dim MyCriteria As String
  199.     Dim sql As String
  200.     'construct a query to put the table in name order
  201.     sql = "select * from [Place Names] order by Name"
  202.     data1.RecordSource = sql
  203.     'refresh the datacontrol with the new order
  204.     data1.Refresh
  205.     'get a name to look for
  206.     MyCriteria = "Name >= '" & InputBox$("Name to find:") & "'"
  207.     'look for the name
  208.     'and find first matching record.
  209.     data1.Recordset.FindFirst MyCriteria
  210.     'if not found, say so and point to the first valid record
  211.     If data1.Recordset.NoMatch Then
  212.     MsgBox "record not found"
  213.     data1.Recordset.MoveFirst
  214.     End If
  215.  
  216. GoTo cmdfindEND
  217. cmdfindERR:
  218.     showerror
  219.     Resume cmdfindEND
  220. cmdfindEND:
  221.  
  222. End Sub
  223.  
  224. Sub cmdNew_Click ()
  225.     On Error GoTo cmdnewERR
  226.     data1.Recordset.AddNew
  227.     text1(0).SetFocus
  228.  
  229. GoTo cmdnewEND
  230. cmdnewERR:
  231.     showerror
  232.     Resume cmdnewEND
  233. cmdnewEND:
  234.  
  235. End Sub
  236.  
  237. Sub cmdUpdate_Click ()
  238.     On Error GoTo cmdupdateERR
  239.     data1.Recordset.Update
  240.  
  241. GoTo cmdupdateEND
  242. cmdupdateERR:
  243.     showerror
  244.     Resume cmdupdateEND
  245. cmdupdateEND:
  246.  
  247. End Sub
  248.  
  249. Sub Form_Load ()
  250.     On Error GoTo formERR
  251.     Dim i As Integer
  252.     'set the database name to the data control
  253.     data1.DatabaseName = ThePath + "USPLACE.MDB"
  254.     'point the data control to our table
  255.     data1.RecordSource = "Place Names"
  256.     'open it up
  257.     data1.Refresh
  258.     'just to show it can be done, get the labels
  259.     'and field names from the tabledefs object.
  260.     'you could also hard code them, or set them in
  261.     'the properties window
  262.     For i = 0 To 4
  263.     label1(i).Caption = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
  264.     text1(i).DataField = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
  265.     Next i
  266.     
  267.     'note -- our table is now in primary key
  268.     'order at this point.
  269.     'The code in the find button event puts it in
  270.     'name order before executing the findfirst
  271.  
  272. GoTo formEND
  273. formERR:
  274.     showerror
  275.     Resume formEND
  276. formEND:
  277.  
  278. End Sub
  279.  
  280. Sub Form_Unload (Cancel As Integer)
  281.     On Error GoTo unloadERR
  282.     data1.Recordset.Close
  283.  
  284. GoTo unloadEND
  285. unloadERR:
  286.     showerror
  287.     Resume unloadEND
  288. unloadEND:
  289.  
  290.  
  291. End Sub
  292.  
  293.